package com.aier.user.common;

import java.util.Calendar;
import java.util.Date;

import com.aier.common.common.Constant;

public class UserBillUtil {

    /**
     * 4种收费方式：
     */
    public static final Long BILL_MONTH = 1L;         //月
    public static final Long BILL_HALF_YEAR = 2L;    //半年 
    public static final Long BILL_YEAR = 3L;        //一年     
    

    /**
     * 获取指定日期的 几个月后的日期
     * @return
     */
    public static Date getDate(Date datestmp,int month_num){
//        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal=Calendar.getInstance();
        cal.setTime(datestmp);
        cal.add(Calendar.MONTH,month_num);//对月份进行计算,减去12个月
        Date date=cal.getTime();
//        System.out.println(date);
        return date;//df.format(date)
          
    }
    
    /**
     * 比较两个日期的大小,true:dat1<dat2 false:dat1>dat2
     * @return
     */
    public static boolean dateCompare(Date dat1, Date dat2) {
        boolean dateComPareFlag = true;
        if (dat2.compareTo(dat1) != 1) {
            dateComPareFlag = false; // 
        }
        return dateComPareFlag;
    }
    
    /**
     * 获取新的 有效截止期
     */ 
    public static Date findNewEdate(Long cid, Integer num, Date edate) {
        Date newEdate = null;
        int month_cid = 0;
        int month_num ;
        if(cid == BILL_MONTH){
            month_cid = 1;
        }
        if(cid == BILL_HALF_YEAR){
            month_cid = Constant.num_6;
        }
        if(cid == BILL_YEAR){
            month_cid = Constant.num_12;
        }
        month_num = month_cid*num;
        
        Date currentdate = new Date();
        if(edate!=null&&(dateCompare(currentdate,edate))){
            newEdate = getDate(edate,month_num);
        }else{
            newEdate = getDate(currentdate,month_num);
        }
        return newEdate;
    }  
    

}
